#ifndef _H_TDF_NODE
#define _H_TDF_NODE

#include <vector>
#include <string>

#include "attribute.h"

using namespace std;

class tdf_content_table;

class tdf_node{

    protected:
        tdf_content_table* parent_table;
        tdf_node* parent;

        unsigned int index;
        vector<tdf_node> childNodes;
        vector<tdf_attribute> attrib;

        bool getChildNodePosAs(tdf_node*,unsigned int*);
        bool getChildNodePosAs(tdf_node*,vector<tdf_node>::iterator*);
        bool getChildNodePosAs(tdf_node*,vector<tdf_node>::reverse_iterator*);

        bool getAttribPosAs(tdf_attribute*,unsigned int*);
        bool getAttribPosAs(tdf_attribute*,vector<tdf_attribute>::iterator*);
        bool getAttribPosAs(tdf_attribute*,vector<tdf_attribute>::reverse_iterator*);

    public:
        tdf_node();
        tdf_node(string*,tdf_content_table*,tdf_node*);
        tdf_node(char*,tdf_content_table*,tdf_node*);
        ~tdf_node();

        variant value;

        void exportNode(FILE*);
        void importNode(FILE*,tdf_content_table* = NULL, tdf_node* = NULL);

        void exportNodeXML(FILE*,string="");

        string getName();
        string getPath();
        unsigned int getIndex();
        unsigned int getNumber();

        tdf_node* addChildNode(string*);
        tdf_node* addChildNode(char*);

        tdf_node* getParentNode();

        unsigned int countChildNode();
        tdf_node* getFirstChildNode();
        tdf_node* getLastChildNode();
        tdf_node* getNextChildNode(tdf_node*);
        tdf_node* getPrevChildNode(tdf_node*);
        tdf_node* getChildNodeAt(unsigned int);

        unsigned int countChildNodeAs(string*);
        unsigned int countChildNodeAs(char*);
        unsigned int countChildNodeAs(unsigned int);
        tdf_node* getFirstChildNodeAs(string*);
        tdf_node* getFirstChildNodeAs(char*);
        tdf_node* getFirstChildNodeAs(unsigned int);
        tdf_node* getLastChildNodeAs(string*);
        tdf_node* getLastChildNodeAs(char*);
        tdf_node* getLastChildNodeAs(unsigned int);
        tdf_node* getNextChildNodeAs(tdf_node*);
        tdf_node* getPrevChildNodeAs(tdf_node*);
        tdf_node* getChildNodeAsAt(string*,unsigned int);
        tdf_node* getChildNodeAsAt(char*,unsigned int);
        tdf_node* getChildNodeAsAt(unsigned int,unsigned int);

        bool deleteChildNode(string*,unsigned int);
        bool deleteChildNode(char*,unsigned int);
        bool deleteChildNode(unsigned int,unsigned int);
        bool deleteChildNode(tdf_node*);
        bool removeNode();

        tdf_attribute* addAttrib(string*);
        tdf_attribute* addAttrib(char*);

        tdf_attribute* getAttrib(string*);
        tdf_attribute* getAttrib(char*);
        tdf_attribute* getAttrib(unsigned int);

        bool hasAttrib(string*);
        bool hasAttrib(char*);
        bool hasAttrib(unsigned int);

        unsigned int countAttrib();
        tdf_attribute* getFirstAttrib();
        tdf_attribute* getLastAttrib();
        tdf_attribute* getNextAttrib(tdf_attribute*);
        tdf_attribute* getPrevAttrib(tdf_attribute*);
        tdf_attribute* getAttribAt(unsigned int);

};

#endif
